unit uFrmBaseImp;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, JvExStdCtrls, JvButton, JvCtrls, JvFooter,
  JvExExtCtrls, JvExtComponent, ExtCtrls, frxExportRTF, frxExportXML,
  frxExportXLS, frxExportHTML, frxClass, frxExportPDF, frxDBSet,
  IBODataset, DBClient, frxExportCSV, frxExportText, frxExportImage,
  frxChBox, uTCorFoco;

type
  TFrmBaseImp = class(TForm)
    JvFooter1: TJvFooter;
    btnImprimir: TJvFooterBtn;
    btnFechar: TJvFooterBtn;
    frxReport: TfrxReport;
    DBDataset: TfrxDBDataset;
    DBFilho1: TfrxDBDataset;
    DBFilho2: TfrxDBDataset;
    frxPDFExport: TfrxPDFExport;
    frxHTMLExport: TfrxHTMLExport;
    frxXLSExport: TfrxXLSExport;
    frxXMLExport: TfrxXMLExport;
    frxRTFExport: TfrxRTFExport;
    frxBMPExport: TfrxBMPExport;
    frxJPEGExport: TfrxJPEGExport;
    frxTIFFExport: TfrxTIFFExport;
    frxGIFExport: TfrxGIFExport;
    frxSimpleTextExport: TfrxSimpleTextExport;
    frxCSVExport: TfrxCSVExport;
    frxCheckBoxObject: TfrxCheckBoxObject;
    CorFoco: TCorFoco;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btnFecharClick(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  protected
    vAntS : String;
    vAnt  : Integer;

    procedure LoadReport(pReport : TfrxReport; pQuery : TIBOQuery; pTitulo : String = ''; pSubTitulo : String =  ''); overload;
    procedure LoadReport(pReport : TfrxReport; pQuery : TClientDataSet; pTitulo : String = ''; pSubTitulo : String =  ''); overload;
  public
    { Public declarations }
  end;

var
  FrmBaseImp: TFrmBaseImp;

implementation

uses
  uDMGeral, Var_Global;

{$R *.dfm}

procedure TFrmBaseImp.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := CaFree;
end;

procedure TFrmBaseImp.btnFecharClick(Sender: TObject);
begin
  Close;
end;

procedure TFrmBaseImp.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then begin
    Key := #0;
    PerForm(Wm_NextDlgCtl,0,0);
  end;
end;

procedure TFrmBaseImp.LoadReport(pReport: TfrxReport; pQuery: TIBOQuery;
  pTitulo, pSubTitulo: String);
begin
  DBDataset.DataSet := pQuery;

  pReport.Variables['Rel_Titulo'   ] := QuotedStr(pTitulo);
  pReport.Variables['Rel_SubTitulo'] := QuotedStr(pSubTitulo);

  pReport.ShowReport;

  if pQuery.Active then
    pQuery.Close;
end;

procedure TFrmBaseImp.LoadReport(pReport: TfrxReport;
  pQuery: TClientDataSet; pTitulo, pSubTitulo: String);
begin
  DBDataset.DataSet := pQuery;

  pReport.Variables['Rel_Titulo'   ] := QuotedStr(pTitulo);
  pReport.Variables['Rel_SubTitulo'] := QuotedStr(pSubTitulo);

  pReport.ShowReport;
end;

procedure TFrmBaseImp.FormCreate(Sender: TObject);
var vCont : Integer;
begin
  for vCont := 0 to ComponentCount - 1 do begin
    if Components[vCont] is TfrxReport then begin
      (Components[vCont] as TfrxReport).Variables['Rel_Usuario'       ] := QuotedStr('ADMIN');
      (Components[vCont] as TfrxReport).Variables['Rel_Empresa_Nome'  ] := QuotedStr('IGREJA SHALOM');
      if FileExists(GS_CAMINHO_EXE + '\Logo.jpg') then
        (Components[vCont] as TfrxReport).Variables['Rel_Empresa_Imagem'] := QuotedStr(GS_CAMINHO_EXE + '\Logo.jpg');
    end;
  end;
end;

procedure TFrmBaseImp.FormActivate(Sender: TObject);
begin
  Screen.OnActiveControlChange := CorFoco.Executar;
end;

procedure TFrmBaseImp.FormDestroy(Sender: TObject);
begin
  Screen.OnActiveControlChange := nil;
end;

end.
